import { Sdk_Platform, OPPO_AD_CONFIG } from '../../frame/constants';

cc.Class({
    extends: cc.Component,

    properties: {
        content: cc.Node
    },


    start() {

    },
    initPage() {
        this.uiBase.checkUibase()
        if (!he.pool.getPool('bagItem')) {
            he.pool.createPoolSync('bagItem', 5, cc.Prefab, 'uimod/bagItem')
        }
    },
    updatePage(param) {
        this.uiBase.checkUibase()
        if (param.add_coin_func) {
            this.add_coin_func = param.add_coin_func
        }
        else {
            this.add_coin_func = null
        }
        if (param.showList) {
            let itemGrp = param.showList
            this.creatItem(itemGrp)
        }
        this.adSwitch(true)
    },

    closeUI() {
        for (let i = (this.content.children.length); i > 0; i--) {
            he.pool.putElement('bagItem', this.content.children[i - 1])
        }
        this.adSwitch(false)
    },


    adSwitch(status) {
        if (status) {
            switch (common.sdk_env) {
                case Sdk_Platform.UC:
                    he.ad.showBanner()
                    break
            }
        } else {
            //  关掉广告
            switch (common.sdk_env) {
                case Sdk_Platform.UC:
                    he.ad.closeBanner()
                    break
            }
        }
    },

    creatItem(grp) {
        let itemGrp = grp
        for (let i = 0; i < itemGrp.length; i++) {
            let itemOne = itemGrp[i].split('_')
            let pre = he.pool.getElement('bagItem')
            pre.parent = this.content
            pre.setPosition(cc.Vec2.ZERO)
            let spt = pre.getComponent('bagItem')
            spt.initInfo(parseInt(itemOne[0]), 1, i)
            spt.setNum(itemOne[1])
        }
    },

    clickGet() {
        if (this.add_coin_func) {
            this.add_coin_func()
            this.uiBase.closePage()
        }
    },
    clickClose() {
        this.uiBase.closePage()
    },

    getAD() {
        qg.navigateToMiniGame({
            pkgName: 'com.demo',
            success: function () {

            },
            fail: function (res) {
                console.log(JSON.stringify(res))
            }
        })
    },

});
